package com.hong.aop;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * <br>前置增强</br>
 * CGLIB
 */
public class BeforeProxy implements MethodInterceptor{

    public Object getProxy(Class cls){
        return Enhancer.create(cls,this);
    }

    @Override
    public Object intercept(Object target, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        before();
        return methodProxy.invokeSuper(target,args);
    }

    private void before() {
        System.out.println("Before");
    }
}
